import { imgRequest, request } from '@/service/request';

/* 获取验证码 */

export function getVerificationCodeApi(timestamp: number) {
  return `/api/auth/captcha/${timestamp}`;
}

/* 登录接口 */
export function fetchLogin(data: any) {
  return request({
    url: '/api/auth/login',
    method: 'post',
    data
  });
}
/* 获取用户信息 */
export function fetchGetUserInfo() {
  return request({
    url: '/api/user/info',
    method: 'get'
  });
}
/* 获取用户信息 */
export function fetchGetUserRoutes() {
  return request({
    url: '/api/menu/getMenuInfo',
    method: 'get'
  });
}

/* region ====== 项目管理 start */
/* 获取项目列表 */
export function getProjectListApi(params: any) {
  return request({
    url: '/api/project/getList',
    method: 'get',
    params
  });
}
/* 获取项目类型 */
export function getProjectTypeApi() {
  return request({
    url: '/api/project/type',
    method: 'get'
  });
}
/* 新增 */
export function projectCreateApi(data: any) {
  return request({
    url: '/api/project',
    method: 'post',
    data
  });
}
/* 编辑 */
export function projectEditApi(data: any) {
  return request({
    url: '/api/project',
    method: 'put',
    data
  });
}
/* 删除 */
export function projectDeleteApi(id: any) {
  return request({
    url: `/api/project/${id}`,
    method: 'delete'
  });
}
/* endregion === 项目管理 end */

/* region ====== 用户管理 start */
/* 列表 */
export function getUserListApi(params: any) {
  return request({
    url: '/api/user/getList',
    method: 'get',
    params
  });
}
/* 新增 */
export function userCreateApi(data: any) {
  return request({
    url: '/api/user',
    method: 'post',
    data
  });
}
/* 编辑 */
export function userEditApi(data: any) {
  return request({
    url: '/api/user',
    method: 'put',
    data
  });
}
/* 删除 */
export function userDeleteApi(id: any) {
  return request({
    url: `/api/user/${id}`,
    method: 'delete'
  });
}
/* 设备权限 */
export function userDevicePermissionApi(data: any) {
  return request({
    url: '/api/host/configUserDevicePermission',
    method: 'post',
    data
  });
}
/* endregion === 用户管理 end */

/* region ====== 单位管理 start */
/* 列表 */
export function getUnitListApi(params: any) {
  return request({
    url: '/api/organization/getList',
    method: 'get',
    params
  });
}

/* 新增 */
export function unitCreateApi(data: any) {
  return request({
    url: '/api/organization',
    method: 'post',
    data
  });
}
/* 编辑 */
export function unitEditApi(data: any) {
  return request({
    url: '/api/organization',
    method: 'put',
    data
  });
}
/* 删除 */
export function unitDeleteApi(id: any) {
  return request({
    url: `/api/organization/${id}`,
    method: 'delete'
  });
}
/* endregion === 单位管理 end */

/* region ====== 设备管理 start */
export function getDeviceListApi(params: any) {
  return request({
    url: '/api/deviceInfo/getList',
    method: 'get',
    params
  });
}

export function switchDevice(data: any) {
  return request({
    url: '/api/deviceInfo/switchController',
    method: 'put',
    data
  });
}

// 获取控制开关
export function requestDeviceControl(data: any) {
  return request({
    url: `/api/deviceInfo/control`,
    method: 'post',
    data
  });
}

export function getDeviceCategoryApi(query: any) {
  return request({
    url: `/api/category/getList`,
    method: 'get',
    params: query
  });
}

// 新增控制器
export function addDigitalDevice(data: any) {
  return request({
    url: '/api/deviceInfo/addDigitalDevice',
    method: 'post',
    data
  });
}

// 新增传感器
export function addAnalogDevice(data: any) {
  return request({
    url: '/api/deviceInfo/addAnalogDevice',
    method: 'post',
    data
  });
}

// 更新控制器
export function updateDigitalDevice(data: any) {
  return request({
    url: '/api/deviceInfo/updateDigitalDevice',
    method: 'put',
    data
  });
}

// 更新控制器
export function updateAnalogDevice(data: any) {
  return request({
    url: '/api/deviceInfo/updateAnalogDevice',
    method: 'put',
    data
  });
}

// 重置周期
export function resetSensorPeriodApi(data: any) {
  return request({
    url: '/api/deviceInfo/resetSensorPeriod',
    method: 'post',
    data
  });
}

// 获取设备详情
export function getDeviceDetailApi(id: any) {
  return request({
    url: `/api/deviceInfo/${id}`,
    method: 'get'
  });
}

// 更新控制器时间表自动控制配置
export function updateDDTimeSC(data: any) {
  return request({
    url: '/api/deviceInfo/updateDigitalDeviceTimerScheduleConfig',
    method: 'put',
    data
  });
}

// 更新控制器上下限自动控制配置
export function updateDDThrSC(data: any) {
  return request({
    url: '/api/deviceInfo/updateDigitalDeviceThresholdConfig',
    method: 'put',
    data
  });
}
// 更新控制器同时控制配置
export function updateDDTTC(data: any) {
  return request({
    url: '/api/deviceInfo/updateDigitalDeviceTimeThresholdConfig',
    method: 'put',
    data
  });
}

export function fetchDeviceList(query: any, pageNo: any, pageSize: any, projectId: any) {
  return request({
    url: `/api/deviceInfo/getList?parentId=0&projectId=${projectId}&pageNo=${pageNo}&pageSize=${pageSize}${query}`,
    method: 'get'
  });
}

// 获取设备折线图
export function getHistoryData4CurveApi(data: any) {
  return request({
    url: `/api/deviceInfo/historyData4Curve`,
    method: 'post',
    data
  });
}

// 导出设备折线图数据
export function exportHistoryExcelData(data: any) {
  return request({
    url: `/api/deviceInfo/historyData`,
    method: 'post',
    data
  });
}

// 删除某个设备
export function destroyDevice(id: any) {
  return request({
    url: `/api/deviceInfo/${id}`,
    method: 'delete'
  });
}
/* endregion === 设备管理 end */

/* region ====== 网关管理 start */
/* 列表 */
export function getCollectionListApi(params: any) {
  return request({
    url: '/api/collection/getList',
    method: 'get',
    params
  });
}

/* 新增 */
export function collectionCreateApi(data: any) {
  return request({
    url: '/api/collection',
    method: 'post',
    data
  });
}
/* 编辑 */
export function collectionEditApi(data: any) {
  return request({
    url: '/api/collection',
    method: 'put',
    data
  });
}
/* 删除 */
export function collectionDeleteApi(id: any) {
  return request({
    url: `/api/collection/${id}`,
    method: 'delete'
  });
}
/* 删除 */
export function getTopicListApi(params: any) {
  return request({
    url: `/api/topic/getList`,
    method: 'get',
    params
  });
}
/* endregion === 网关管理 end */

/* region ====== 终端管理 start */
/* 列表 */
export function getHostListApi(params: any) {
  return request({
    url: '/api/host/getList',
    method: 'get',
    params
  });
}

/* 新增 */
export function hostCreateApi(data: any) {
  return request({
    url: '/api/host',
    method: 'post',
    data
  });
}
/* 编辑 */
export function hostEditApi(data: any) {
  return request({
    url: '/api/host',
    method: 'put',
    data
  });
}
/* 删除 */
export function hostDeleteApi(id: any) {
  return request({
    url: `/api/host/${id}`,
    method: 'delete'
  });
}
/* endregion === 终端管理 end */

/* region ====== 告警管理 start */
export function getWarningListApi(params: any) {
  return request({
    url: '/api/analogAlarmRecord/getList',
    method: 'get',
    params
  });
}
/* endregion === 告警管理 end */

/* region ====== 养殖池管理 start */
export function getFarmListApi(params: any) {
  return request({
    url: '/api/farm/getList',
    method: 'get',
    params
  });
}

export function farmDeleteApi(id: any) {
  return request({
    url: `/api/farm/${id}`,
    method: 'delete'
  });
}
// 新增
export function farmCreateApi(data: any) {
  return request({
    url: '/api/farm',
    method: 'post',
    data
  });
}

export function farmEditApi(data: any) {
  return request({
    url: '/api/farm',
    method: 'put',
    data
  });
}
/* endregion === 告警管理 end */

/* region ====== 监控管理 start */
export function getVideoUrlApi(params: any) {
  return request({
    url: '/api/videoMonitor/getVideoUrl',
    method: 'get',
    params
  });
}

export function getVideoMonitorListApi(params: any) {
  return request({
    url: '/api/videoMonitor/getList',
    method: 'get',
    params
  });
}

export function videoMonitorDeleteApi(id: any) {
  return request({
    url: `/api/videoMonitor/${id}`,
    method: 'delete'
  });
}

// 新增
export function videoMonitorCreateApi(data: any) {
  return request({
    url: '/api/videoMonitor',
    method: 'post',
    data
  });
}

export function videoMonitorEditApi(data: any) {
  return request({
    url: '/api/videoMonitor',
    method: 'put',
    data
  });
}
/* endregion === 告警管理 end */

export function getImg(params: any) {
  return imgRequest({
    url: '/api/file/download',
    method: 'get',
    params,
    responseType: 'blob'
  });
}

/* region ====== 外链管理 start */
export function getProjectLinkListApi(params: any) {
  return request({
    url: '/api/projectLink/getList',
    method: 'get',
    params
  });
}
export function projectLinkCreateApi(data: any) {
  return request({
    url: '/api/projectLink',
    method: 'post',
    data
  });
}
export function projectLinkEditApi(data: any) {
  return request({
    url: '/api/projectLink',
    method: 'put',
    data
  });
}
export function projectLinkDeleteApi(id: any) {
  return request({
    url: `/api/projectLink/${id}`,
    method: 'delete'
  });
}
/* endregion === 外链管理 end */

/* region ====== 鱼池分类 start */
export function getFarmLabelListApi(params: any) {
  return request({
    url: '/api/farmLabel/getList',
    method: 'get',
    params
  });
}
export function farmLabelCreateApi(data: any) {
  return request({
    url: '/api/farmLabel',
    method: 'post',
    data
  });
}
export function farmLabelEditApi(data: any) {
  return request({
    url: '/api/farmLabel',
    method: 'put',
    data
  });
}
export function farmLabelDeleteApi(id: any) {
  return request({
    url: `/api/farmLabel/${id}`,
    method: 'delete'
  });
}
/* endregion === 鱼池分类 end */

/* region ====== 设备曲线导出 start */
/* endregion === 设备曲线导出 end */
